package org.codingq92.frame.springmvc.bean;

import lombok.Getter;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.Method;

/**
 * 每个单独请求的基本bean
 *
 * @author CodingQ92
 */
@Getter
public class MyWebHandler {

    public static final int JSON = 0;
    public static final int HTML = 1;
    public static final int VIEW = 2;

    private final Object controllerBean;
    private final Method method;
    private final int resultType;

    public MyWebHandler(Object controllerBean, Method method) {
        this.controllerBean = controllerBean;
        this.method = method;
        this.resultType = resovleResultType(method);
    }

    /**
     * 解析返回值类型
     *
     * @param method 方法
     * @return 返回值类型
     */
    private int resovleResultType(Method method) {
        if (method.isAnnotationPresent(ResponseBody.class)) {
            return JSON;
        }
//        if (method.getReturnType() == ModelAndView.class) {
//            return ResultType.LOCAL;
//        }
        return HTML;
    }
}
